
// Rectangle.cpp: implementation of the Rectangle class.
//
//////////////////////////////////////////////////////////////////////

#include "Rectangle.h"

const double minBoundary = 0.0;
const double highBoundary = 100.0;
const compareFunc compareMinBoundary = isGreat;
const compareFunc compareHighBoundary = isLessOrEqual;

Rectangle::Rectangle(const double length, const double width)
:length_m(getFloorOfValue(length, 2)), width_m(getFloorOfValue(width, 2))
{
}

bool Rectangle::isValid() const 
{
    return (checkInputValid(length_m, minBoundary, compareMinBoundary)
            && checkInputValid(length_m, highBoundary, compareHighBoundary)
            && checkInputValid(width_m, minBoundary, compareMinBoundary)
	    && checkInputValid(width_m, highBoundary, compareHighBoundary));
}

double Rectangle::getArea() const
{
    return isValid() ? getRoundOfValue(length_m * width_m, 2) : 0.0;
};

double Rectangle::getPerimeter() const
{
    return isValid() ? 2 * (length_m + width_m) : 0.0;
};

void Rectangle::reset(const Rectangle& other)
{
    if (other.isValid())
    {
        *this = other;
    }
}


